var utils = require("../../../utils/util.js");
var app = getApp();
// pages/movies/movie-detail/movie-detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    movie:{}
  },
  onLoad: function (options) {
    var movieId = options.id;
    var movieDetailUrl = app.globalData.doubanBase + "/v2/movie/subject/" + movieId;
    utils.http(movieDetailUrl, this.processDoubanData);
    console.log(movieId)
  }, 
  onMovieTap: function (event) {
    var moviesId = event.currentTarget.dataset.movieid;
    console.log()
    wx.navigateTo({
      url: 'movie-detail/movie-detail?id=' + moviesId,
    })
  },
  processDoubanData:function(data){
    if(!data){
      return;
    }
    var director ={
      avatars : "",
      name : "",
      id : ""
    }
    if (data.directors[0] != null){
      if (data.directors[0].avatars != null){
        director.avatars = data.directors[0].avatars.large
      }
      director.name = data.directors[0].name
      director.id = data.directors[0].id
    }
    var movie = {
      country: data.countries[0],
      movieImg: data.images ? data.images.large:"",
      originaltitle: data.original_title,
      stars: utils.convertToStarsArray(data.rating.stars),
      count: data.reviews_count,
      summary:data.summary,
      director: director,
      wishcount: data.wish_count,
      title:data.title,
      commentscount: data.comments_count,
      year:data.year,
      casts: utils.convertToCastString(data.casts),
      castsInfo: utils.convertToCastInfos(data.casts),
      score: data.rating.average,
      generes: data.genres.join("、")
    }
    console.log(movie)
    this.setData({
      movie:movie
    })
  },
  viewMoviePostImg: function (e) {
    var src = e.currentTarget.dataset.src;
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: [src] // 需要预览的图片http链接列表
    })
  },
})